$(function () {
    let form = $('.loginForm')
    form.submit(async function (e) {
        //阻止默认事件
        e.preventDefault()

        //获得当前元素的值
        let username = $('#user').val()
        let userPassword = $('#mima').val()

        //准备参数
        let options = {
            url: 'http://146.56.230.35:3007/users/login',
            type: 'POST',
            data: {
                username,
                userPassword,
            },
        }

        //发起请求
        let res = await request(options)
        console.log(res)
        if(res.code!==200){
            return alert(res.msg)
        }
        sessionStorage.setItem('user_login',JSON.stringify(res))
        location='welcome.html'
    })
})